<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Ohne_Titel_1</title>

<script type="text/javascript" src="jquery-ui-1.8.18.custom/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.18.custom/js/jquery-ui-1.8.18.custom.min.js"></script>
<link rel="stylesheet" href="timetable_style.css">



          
</head>

<body>


<?php
session_start(); 
?> 

<?php 
if(!isset($_SESSION["username"])) 
   { 
   echo "Bitte erst <a href=\"login.html\">einloggen</a>"; 
   exit; 
   } 
?> 


<?php

$username = $_SESSION["username"];

$verbindung = mysql_connect("localhost", "root" , "") or die("Verbindung zur Datenbank konnte nicht hergestellt werden"); 
mysql_select_db("Timetable") or die ("Datenbank konnte nicht ausgewählt werden"); 


$sql = "Select DraggablesAnzahl from user where username ='$username' ";

$res = mysql_query ($sql);

$dsatz = mysql_fetch_assoc($res);

$DraggablesAnzahl =$dsatz ["DraggablesAnzahl"];

echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo $DraggablesAnzahl;
?>

<form style="position:absolute; top:0px; left:0px;" name="myform" id="myform" action="timetable-update.php" method="post">
<?php
for ($i=1;$i<=$DraggablesAnzahl;$i++)
{
echo"<input type='text' id='PositionTop".$i."'   name='PositionTop".$i."' value=''>";
echo"<input type='text' id='PositionLeft".$i."'  name='PositionLeft".$i."' value=''>";

echo"PositionTop".$i;
echo"PositionLeft".$i;
}
?>
<input type="submit" name="Speichern" value="Speichern">

</form>


<?php

for ($i=1;$i<=$DraggablesAnzahl;$i++)
{
echo"<script>";
echo"	$(function() {";
echo"  	          $( '#draggable".$i."' ).draggable({ ";	             
echo"	             stop: function(event, ui) { ";
	              
echo"	          var pos".$i." = ui.position;";
//echo"	          alert (pos".$i.".top+', '+pos".$i.".left);";

echo"             document.myform.PositionTop".$i.".value = pos".$i.".top;   ";
echo"             document.myform.PositionLeft".$i.".value = pos".$i.".left;   ";
       	       	          
	              	       	           	              
echo"	          }";	             

echo"            });";	                       		
echo"     });";          
echo"</script>";




//Werte aus Datenbank in Draggables

mysql_connect ("localhost","root","");
mysql_select_db("timetable");

$sql = "Select PositionTop$i, PositionLeft$i from user where username ='$username' ";

$res = mysql_query ($sql);

$dsatz = mysql_fetch_assoc($res);

$DBPositionTop =$dsatz ["PositionTop$i"];
$DBPositionLeft =$dsatz ["PositionLeft$i"];


echo $DBPositionTop;
echo $DBPositionLeft;

//Werte aus Datenbank in Draggables Ende


echo"<div style=' top:' . $DBPositionTop . 'px; left:' . $DBPositionLeft . 'px;' class='draggable' id='draggable".$i."'>";
echo"	<p>Nummer".$i."</p>";
echo"</div>";

}

?>






	





<div id="dragpos"></div>





</body>

</html>
